package cn.petplatform.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * 集成Swagger
 *
 * @author LNL
 * @date 2021/4/20 20:16
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    //配置Swagger的Docket的实例
    @Bean
    public Docket createDocket(Environment environment) {
        //设置要显示的Swagger环境,在dev环境下显示
        Profiles profiles = Profiles.of("dev");

        //判断是否处在自己设定的环境中
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("Project")   //分组名称
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.petplatform.petback.controller"))//指定扫描的路径
                .build();

    }

    @Bean
    public ApiInfo apiInfo() {
        Contact contact = new Contact("schoolProject","","");
        return new ApiInfo(
                "项目开发文档",
                "开发文档",
                "v1.0",
                "",
                contact,
                "Apache2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>()
        );
    }


}
